﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;
using Microsoft.Phone.Info;

namespace UnionPay4WP
{
    public class DeviceInfo
    {

 #region 加载手机的基本信息 + private void BindBaseInfo()
         /// <summary>
 /// 加载手机的基本信息
 /// </summary>
         public static string BindBaseInfo()
         {
 
             StringBuilder sb = new StringBuilder();
 
             //设备制造商名称
             string str = DeviceStatus.DeviceManufacturer.ToString();
            // UnionPay4WP.MainPage1.textBlock1.Text = "制造商:   " + str;
 
             //设备名称
             str = DeviceStatus.DeviceName.ToString();
             sb.AppendLine("设备名称:   " + str);
             sb.AppendLine();
 
             //设备运行的固件版本
             str =Environment.OSVersion.Version.ToString();// DeviceStatus.DeviceFirmwareVersion.ToString();
             sb.AppendLine("固件版本:   " + str);
             sb.AppendLine();
 
             //设备运行的硬件版本
             str = DeviceStatus.DeviceHardwareVersion.ToString();
             sb.AppendLine("硬件版本:   " + str);
             sb.AppendLine();
 
 
             //使用外部电源还是手机电源
             str = DeviceStatus.PowerSource.ToString();
             sb.AppendLine("手机电源:   " + str);
             sb.AppendLine();
 
             //是否已经部署设备的物理硬件键盘
             if (DeviceStatus.IsKeyboardDeployed == true)
             {
                 sb.AppendLine("物理键盘:   已部署");
             }
             else
             {
                 sb.AppendLine("物理键盘:   未部署");
             }
             sb.AppendLine();
 
             //设备是否包含物理硬件键盘
             if (DeviceStatus.IsKeyboardPresent == true)
             {
                 sb.AppendLine("虚拟键盘:   已内置");
             }
             else
             {
                 sb.AppendLine("虚拟键盘:   未内置");
             }
             sb.AppendLine();
 
             string anonymousUserId = "";
             try
             {
                 string anid = UserExtendedProperties.GetValue("ANID") as string;
                 anonymousUserId = anid.Substring(2, 32);
             }
             catch (Exception)
             {
 
                 anonymousUserId = "手机还没有绑定Live ID";
             }
             sb.AppendLine("用户唯一标识:   " + anonymousUserId);
             sb.AppendLine();
 
             //设备唯一标识
             byte[] byteArray = DeviceExtendedProperties.GetValue("DeviceUniqueId") as byte[];
             //string strTemp = "";
             
             //foreach (byte b in byteArray)
             //{
             //    strTemp = b.ToString();
             //    if (1 == strTemp.Length)
             //    {
             //        strTemp = "00" + strTemp;
             //    }
             //    else if (2 == strTemp.Length)
             //    {
             //        strTemp = "0" + strTemp;
             //    }
             //    strDeviceUniqueID += strTemp;
             //}
             string strDeviceUniqueID = BitConverter.ToString(byteArray).Replace("-", "");
 
             sb.AppendLine("设备唯一标识:   " + strDeviceUniqueID);
             sb.AppendLine();
 
             return sb.ToString();
 
             //str = MediaCapabilities.IsMultiResolutionVideoSupported.ToString();
 //sb.AppendLine("是否支持多分辨率编码的视频的平滑流：" + str.ToString());
 
         } 
         #endregion
 
         #region Device信息 + private void BindStorage()
 /// <summary>
 /// 获取DeviceUniqueID信息
 /// </summary>
         public static string getDeviceUniqueID()
         {
             string deviceUniqueID = "";
             //设备唯一标识
             byte[] byteArray = DeviceExtendedProperties.GetValue("DeviceUniqueId") as byte[];
             deviceUniqueID = BitConverter.ToString(byteArray).Replace("-", "");
             return deviceUniqueID;
         }

 /// <summary>
 /// 获取设备型号信息
 /// </summary>
         public static string getDeviceName()
         {
             //设备唯一标识
             string strDeviceName = DeviceStatus.DeviceName.ToString();
            // string strDeviceName= DeviceExtendedProperties.GetValue("DeviceName").ToString();
             
             return strDeviceName;
         }
         /// <summary>
         /// 获取设备型号信息
         /// </summary>
         public static string getOSVersion()
         {
             //设备OS
             string OSVersion = "WP "+Environment.OSVersion.Version.ToString();            

             return OSVersion;
         }
         
         #endregion
    }

   
}
